package com.rt.tmpt.service.impl;

import com.rt.tmpt.bean.A1TemplateTable;
import com.rt.tmpt.dao.intf.IA1TemplateTableDao;
import com.rt.tmpt.dao.intf.ITemplateDao;
import com.rt.tmpt.dto.Result;
import com.rt.tmpt.service.ITemplate4TreegridService;
import com.rt.tmpt.utils.JsonMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@Slf4j
public class Template4TreegridService implements ITemplate4TreegridService {



	@Resource private IA1TemplateTableDao a1TemplateTableDao;
	@Resource private ITemplateDao templateDao;



	@Override
	public Result paginationBySearch(String paramJson, Map<String, Object> paramMap111) {

		Result resultObj = new Result();
		Map<String, Object> resultMap = null;
		try{
			System.out.println(paramJson);
			Map<String, String[]> paramMap1 = JsonMap.json2Map(paramJson);
			String keyRandom = paramMap1.get("_keyRandom")[0];
			System.out.println(keyRandom);

			//Search search = new Search();
			//search.addFilterEqual("keyRandom", keyRandom);
			A1TemplateTable a1TemplateTable = new A1TemplateTable();
			a1TemplateTable.setKeyRandom(keyRandom);
			A1TemplateTable templateTable = a1TemplateTableDao.findOne(Example.of(a1TemplateTable)).get();

			String[] params = {"-1","0","0"};

			resultObj = templateDao.templateSearch4treegrid(templateTable, paramMap1, params);

			return resultObj;

		}catch (Exception e) {
			e.printStackTrace();
			return resultObj.fault(e.getLocalizedMessage());
		}

	}




}
